Subject.js ➔ describe(ꞌSubjectꞌ)   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 135

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 135
rs 8.2857

6 Functions

Rating   Name   Duplication   Size   Complexity  
B Subject.js ➔ ... ➔ it(ꞌCreate with mixed dataꞌ) 0 31 1
A Subject.js ➔ ... ➔ it(ꞌconstructor does not copy instancesꞌ) 0 5 1
B Subject.js ➔ ... ➔ it(ꞌBuildꞌ) 0 26 1
B Subject.js ➔ ... ➔ it(ꞌCreate with JSONꞌ) 0 31 1
B Subject.js ➔ ... ➔ it(ꞌtoJSONꞌ) 0 27 1
A Subject.js ➔ ... ➔ it(ꞌCreate plainꞌ) 0 6 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var assert = require('chai').assert,
2
    GedcomX = require('../../');
3
4
describe('Subject', function(){
5
  
6
  it('Create plain', function(){
7
    var newSubject = new GedcomX.Subject(),
8
        subject = GedcomX.Subject();
9
    assert.instanceOf(newSubject, GedcomX.Subject, 'An instance of Subject is not returned when calling the constructor with new.');
10
    assert.instanceOf(subject, GedcomX.Subject, 'An instance of Subject is not returned when calling the constructor without new.');
11
  });
12
  
13
  it('Create with JSON', function(){
14
    var subject = GedcomX.Subject({
15
      extracted: true,
16
      evidence: [
17
        { 
18
          resource: 'http://example.com',
19
          attribution: {
20
            created: 1248942374
21
          }
22
        }
23
      ],
24
      media: [
25
        {
26
          id: 'source-ref',
27
          description: 'http://some/uri',
28
          attribution: {
29
            created: 11121211112
30
          }
31
        }
32
      ],
33
      identifiers: {
34
        '$': 'SOMEID'
35
      }
36
    });
37
    assert(subject.isExtracted());
38
    assert.lengthOf(subject.getEvidence(), 1);
39
    assert.instanceOf(subject.getEvidence()[0], GedcomX.EvidenceReference);
40
    assert.lengthOf(subject.getMedia(), 1);
41
    assert.instanceOf(subject.getMedia()[0], GedcomX.SourceReference);
42
    assert.instanceOf(subject.getIdentifiers(), GedcomX.Identifiers);
43
  });
44
  
45
  it('Create with mixed data', function(){
46
    var subject = GedcomX.Subject({
47
      extracted: true,
48
      evidence: [
49
        GedcomX.EvidenceReference({ 
50
          resource: 'http://example.com',
51
          attribution: {
52
            created: 1248942374
53
          }
54
        })
55
      ],
56
      media: [
57
        GedcomX.SourceReference({
58
          id: 'source-ref',
59
          description: 'http://some/uri',
60
          attribution: {
61
            created: 11121211112
62
          }
63
        })
64
      ],
65
      identifiers: {
66
        '$': 'SOMEID'
67
      }
68
    });
69
    assert(subject.isExtracted());
70
    assert.lengthOf(subject.getEvidence(), 1);
71
    assert.instanceOf(subject.getEvidence()[0], GedcomX.EvidenceReference);
72
    assert.lengthOf(subject.getMedia(), 1);
73
    assert.instanceOf(subject.getMedia()[0], GedcomX.SourceReference);
74
    assert.instanceOf(subject.getIdentifiers(), GedcomX.Identifiers);
75
  });
76
  
77
  it('Build', function(){
78
    var subject = GedcomX.Subject()
79
      .setExtracted(true)
80
      .addEvidence({ 
81
        resource: 'http://example.com',
82
        attribution: {
83
          created: 1248942374
84
        }
85
      })
86
      .addMedia({
87
        id: 'source-ref',
88
        description: 'http://some/uri',
89
        attribution: {
90
          created: 11121211112
91
        }
92
      })
93
      .setIdentifiers({
94
        '$': 'SOMEID'
95
      });
96
    assert(subject.isExtracted());
97
    assert.lengthOf(subject.getEvidence(), 1);
98
    assert.instanceOf(subject.getEvidence()[0], GedcomX.EvidenceReference);
99
    assert.lengthOf(subject.getMedia(), 1);
100
    assert.instanceOf(subject.getMedia()[0], GedcomX.SourceReference);
101
    assert.instanceOf(subject.getIdentifiers(), GedcomX.Identifiers);
102
  });
103
  
104
  it('toJSON', function(){
105
    var subjectData = {
106
        extracted: true,
107
        evidence: [
108
          { 
109
            resource: 'http://example.com',
110
            attribution: {
111
              created: 1248942374
112
            }
113
          }
114
        ],
115
        media: [
116
          {
117
            id: 'source-ref',
118
            description: 'http://some/uri',
119
            attribution: {
120
              created: 11121211112
121
            }
122
          }
123
        ],
124
        identifiers: {
125
          '$': 'SOMEID'
126
        }
127
      },
128
      subject = GedcomX.Subject(subjectData);
129
    assert.deepEqual(subjectData, subject.toJSON());
130
  });
131
  
132
  it('constructor does not copy instances', function(){
133
    var obj1 = GedcomX.Subject();
134
    var obj2 = GedcomX.Subject(obj1);
135
    assert.strictEqual(obj1, obj2);
136
  });
137
  
138
});